package com.pearadmin.pro.modules.experiment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.modules.experiment.entity.ExperimentMajor;
import com.pearadmin.pro.modules.experiment.mapper.ExperimentMajorDao;
import com.pearadmin.pro.modules.experiment.service.ExperimentMajorService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ExperimentMajorServiceImpl extends ServiceImpl<ExperimentMajorDao, ExperimentMajor> implements ExperimentMajorService {

    @Resource
    private ExperimentMajorDao experimentMajorDao;


    @Override
    public List<ExperimentMajor> filtrate() {
        return experimentMajorDao.filtrate();
    }

    @Override
    public List<ExperimentMajor> getClssify(Integer id) {
        return experimentMajorDao.getClssify(id);
    }

    @Override
    public List<ExperimentMajor> tree() {
        return toTree(experimentMajorDao.tree(),0);
    }

    public List<ExperimentMajor> toTree(List<ExperimentMajor> tree, Integer parent) {
        List<ExperimentMajor> list = new ArrayList<>();
        for (ExperimentMajor dept : tree) {
            if (parent.equals(dept.getParentId())) {
                dept.setChildren(toTree(tree, dept.getId()));
                list.add(dept);
            }
        }
        return list;
    }
}
